package com.gray.pool.async;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.task.AsyncTaskExecutor;

/**
 * Created on 2019/6/23.
 *
 * @author Grak
 * @since 1.0
 */
@Configuration
@PropertySource(value = {"classpath:executorAsync.properties"})
@ConfigurationProperties(prefix = "common")
public class ThreadPoolCommonConfiguration extends ThreadPoolConfiguration {

    private int poolSize = Runtime.getRuntime().availableProcessors() + 1;

    @Bean("commonExecutor")
    public AsyncTaskExecutor MessageExecutor() {
        return taskExecutor();
    }

    @Override
    protected int initCorePoolSize() {
        return poolSize;
    }

    @Override
    protected int initQueueCapacity() {
        return 800;
    }

    @Override
    protected int initKeepAliveSeconds() {
        return 0;
    }

    @Override
    protected String initThreadNamePrefix() {
        return "common_async_executor";
    }
}
